﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
namespace ProjetoFinal
{
    public class Leaf
    {
        public Texture2D texture;
        int rateMove;
        public Rectangle rectCollision, rectDraw;
   
        public Leaf(int rateMove, Rectangle rectCollision, Rectangle rectDraw)
        {
            this.rateMove = rateMove;
            this.rectCollision = rectCollision;
            this.rectDraw = rectDraw;
        }

        public void LoadContent(ContentManager content)
        {
            texture = content.Load<Texture2D>("leaf");
        }


        public void Move(KeyboardState nowKeybord, KeyboardState oldKeyboard)
        { // limites da tela
            if (!(rectDraw.X >= 1024 - rectDraw.Width))//se o x do rectdraw NÃO for maior do que o tamanho da tela menos a largura dele
            {
                if (nowKeybord.IsKeyDown(Keys.Right))
                {
                    rectCollision.X += rateMove;
                    rectDraw.X += rateMove;
                }
            }

            if (rectDraw.X > 0) // se o x do rectdraw for maior do 0
            {
                if (nowKeybord.IsKeyDown(Keys.Left))
                {
                    rectCollision.X -= rateMove;
                    rectDraw.X -= rateMove;
                }
            }

        }


        public void BackToPosition(ref bool lostLife)
        { // posição inicial da folha
            if (lostLife)
            {
                rectCollision.X = 400;
                rectCollision.Y = 700;
                rectDraw.X = 360;
                rectDraw.Y = 700;
                lostLife = false;
            }
        }


        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(texture, rectDraw, Color.White);
        }
    }
}
